import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);

  //接口跨越
  app.enableCors({
    origin: /http:\/\/.+/,
    credentials: true,
    methods: "PUT,POST,GET,DELETE,OPTIONS",
    exposedHeaders: "*"
  })

  //添加验证管道
  app.useGlobalPipes(new ValidationPipe())

  //静态文件路径
  app.useStaticAssets("public", {
    prefix: "/public"
  })
  app.useStaticAssets("dist/public", {
    prefix: "/public"
  })


  //信任代理
  app.set('trust proxy', 1);


  //Swagger 接口文档
  const options = new DocumentBuilder()
    .setTitle('活码系统接口文档')
    .setDescription('活码系统')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api-doc', app, document);

  //http端口
  await app.listen(9070);

}
bootstrap(); 